<!-- components/GlobalLoading.vue -->
<template>
    <transition name="fade">
        <div v-if="isLoading" class="global-loading">
            <transition name="content">
                <div class="first-loading-wrap">
                    <span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
                    <div class="loading-text">加载中...</div>
                </div>
            </transition>
        </div>
    </transition>
</template>

<script>
export default {
    data() {
        return {
            isLoading: false,
            count: 0
        }
    },
    methods: {
        show() {
            this.count++
            this.isLoading = true
        },
        hide() {
            this.count--
            if (this.count <= 0) {
                this.count = 0
                this.isLoading = false
            }
        }
    }
}
</script>

<style scoped>
.global-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.03);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999999999;
}

/* 背景遮罩层动画 */
.fade-enter-active,
.fade-leave-active {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
}

.fade-enter-to,
.fade-leave-from {
    opacity: 1;
}

/* 内容动画 */
.content-enter-active,
.content-leave-active {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.content-enter-from,
.content-leave-to {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
}

.content-enter-to,
.content-leave-from {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.first-loading-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: -50px;
    padding: 20px 40px;
    border-radius: 10px;
}

.dot {
    position: relative;
    box-sizing: border-box;
    display: inline-block;
    width: 50px;
    height: 50px;
    font-size: 50px;
    transform: rotate(45deg);
    animation: ant-rotate 1.2s infinite linear;
}

.dot i {
    position: absolute;
    display: block;
    width: 24px;
    height: 24px;
    background-color: #1890ff;
    border-radius: 100%;
    opacity: 0.3;
    transform: scale(0.75);
    transform-origin: 50% 50%;
    animation: ant-spin-move 1s infinite linear alternate;
}

.dot i:nth-child(1) {
    top: 0;
    left: 0;
}

.dot i:nth-child(2) {
    top: 0;
    right: 0;
    animation-delay: 0.4s;
}

.dot i:nth-child(3) {
    right: 0;
    bottom: 0;
    animation-delay: 0.8s;
}

.dot i:nth-child(4) {
    bottom: 0;
    left: 0;
    animation-delay: 1.2s;
}

@keyframes ant-rotate {
    to {
        transform: rotate(405deg);
    }
}

@keyframes ant-spin-move {
    to {
        opacity: 1;
    }
}

.loading-text {
    margin-top: 16px;
    font-size: 16px;
    color: #1890ff;
} 

</style>